﻿using System;
using FluentNHibernate.Mapping;
using Konekcija.Core.Reporting.Dto.Application.Security;

namespace Konekcija.Core.Reporting.Mappings.Security
{
    
    public class DeveloperApiPermissionMap : ClassMap<DeveloperApiPermission>
    {
        public DeveloperApiPermissionMap()
        {
            Schema("security");
            Table("DeveloperApiPermissions");

            Id(x => x.Id).GeneratedBy.GuidComb().Not.Nullable();

            Map(x => x.DeveloperApiKeyId).Not.Nullable();
            Map(x => x.Token).Not.Nullable();
            Map(x => x.Allow).Not.Nullable();
            Map(x => x.DateCreated).Not.Nullable();

            HasMany(x => x.MobileDevices)
                .Inverse()
                .AsBag()
                .Key(k => k.Not.Nullable())
                .KeyColumn("DeveloperApiPermissionId")
                .Fetch.Join()
                .ForeignKeyCascadeOnDelete()
                .Cascade.Delete()
                .Where("Allow = 0");
        }
    }
}